package com.xoa.service.hr.impl;

import com.xoa.dao.department.DepartmentMapper;
import com.xoa.dao.hr.HrStaffLaborSkillsMapper;
import com.xoa.dao.sms2.Sms2PrivMapper;
import com.xoa.dao.users.UsersMapper;
import com.xoa.model.department.Department;
import com.xoa.model.enclosure.Attachment;
import com.xoa.model.hr.HrStaffLaborSkills;
import com.xoa.model.hr.HrStaffLaborSkillsWithBLOBs;
import com.xoa.model.users.Users;
import com.xoa.util.*;
import com.xoa.util.common.L;
import com.xoa.util.common.log.FileUtils;
import com.xoa.util.common.session.SessionUtils;
import com.xoa.util.page.PageParams;
import com.xoa.util.sendUtil.send;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.stereotype.Service;
import com.xoa.service.hr.HrStaffLaborSkillsService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 *    创建作者:  李阳
 *    创建日期： 2018-07-18 11:22
 *    介绍：劳动信息
 */
@Service
public class HrStaffLaborSkillsServiceImpl implements HrStaffLaborSkillsService{
    //注入mybatis
    @Resource
    private HrStaffLaborSkillsMapper hrStaffLaborSkillsMapper;
    @Resource
    UsersMapper usersMapper;
    @Resource
    DepartmentMapper departmentMapper;
    @Resource
    private Sms2PrivMapper sms2PrivMapper;
    /**
     * 查询全部劳动技能信息
     * @return
     */
    @Override
    public ToJson<HrStaffLaborSkills> getAllHrStaffLaborSkills(Integer page,Integer pageSize,boolean useFlag,String staffName) {
        ToJson<HrStaffLaborSkills> toJson = new ToJson<HrStaffLaborSkills>(1, "error");
        PageParams pageParams = new PageParams(); //分页
        pageParams.setPage(page);
        pageParams.setPageSize(pageSize);
        pageParams.setUseFlag(useFlag);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("page", pageParams);
        map.put("staffName",staffName);
        try{
            List<HrStaffLaborSkills> list=hrStaffLaborSkillsMapper.getAllHrStaffLaborSkills(map);
            if (list.size() > 0) {
                for(int i=0;i<list.size();i++){
                    Users user=usersMapper.findUsersByuserId(list.get(i).getStaffName()); //根据 id 找名字
                    if(user!=null){
                        list.get(i).setStaffName(user.getUserName());
                    }else{
                        list.get(i).setStaffName("单位员工不存在");
                    }
                }
                toJson.setTotleNum(hrStaffLaborSkillsMapper.skillsCount());//数据总条数
                toJson.setObj(list);
                toJson.setMsg("ok");
            } else {
                toJson.setMsg("劳动技能信息为空");
            }
            toJson.setFlag(0);
        }catch (Exception e){
            toJson.setMsg(e.getMessage());
            L.e("HrStaffLaborSkillServiceImpl getAllHrStaffLaborSkills:" + e);
        }
        return toJson;
    }
    /**
     * 根据 SKILLS_ID 查询全部劳动技能信息
     * @return
     */
    @Override
    public ToJson<HrStaffLaborSkills> getStaffBySkillsId(HttpServletRequest request,Integer skillsId){
        ToJson<HrStaffLaborSkills> toJson = new ToJson<HrStaffLaborSkills>(1, "error");
      try{
          HrStaffLaborSkills staff=hrStaffLaborSkillsMapper.getStaffBySkillsId(skillsId);
          //附件处理
          List<Attachment> attachmentList=new ArrayList<Attachment>();
          if(staff.getAttachmentName()!=null&&!"".equals(staff.getAttachmentName())){
              attachmentList= GetAttachmentListUtil.returnAttachment(staff.getAttachmentName(),staff.getAttachmentId(),"xoa" + (String) request.getSession().getAttribute("loginDateSouse"), GetAttachmentListUtil.INCENTIVE);
          }
          staff.setAttachmentList(attachmentList);
          if (staff!=null) {
              if(staff.getSpecialWork().equals("1")){
                  staff.setSpecialWork("是");
              }else{
                  staff.setSpecialWork("否");
              }
              if( staff.getSkillsCertificate().equals("1")){
                  staff.setSkillsCertificate("是");
              }else{
                  staff.setSkillsCertificate("否");
              }
              if(staff.getStaffName()!=null){
                      Users user=usersMapper.findUsersByuserId( staff.getStaffName()); //根据 id 找名字
                      staff.setStaffName(user.getUserName());
              }
              toJson.setObject(staff);
              toJson.setMsg("ok");
          } else {
              toJson.setMsg("劳动技能信息为空");
          }
           String phone="13141018647";
          Cookie redisSessionId = CookiesUtil.getCookieByName(request, "redisSessionId");
          Users users = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(),redisSessionId);
          Integer deptId=users.getDeptId();
          Department department=departmentMapper.getFatherDept(deptId);
          String ecpId="";
          String message="测试";
          if(department!=null){
              ecpId=department.getSmsGateAccount();
          }else {
              toJson.setMsg("请先设置部门号");
          }
          send.sms(phone,ecpId,message,users.getByname(),users.getByname());
          toJson.setFlag(0);
      }catch (Exception e){
          toJson.setMsg(e.getMessage());
          L.e("HrStaffLaborSkillServiceImpl getStaffBySkillsId:" + e);
      }

       return toJson;
  }
    @Override
    public ToJson<HrStaffLaborSkills> getStaffInfo(HttpServletRequest request, HttpServletResponse response,HrStaffLaborSkills hrStaffLaborSkills,Integer page, Integer pageSize, boolean useFlag, String export){
        ToJson<HrStaffLaborSkills> toJson = new ToJson<HrStaffLaborSkills>();
        try{
            if(export==null){
                export="0";
            }
            //分页
            PageParams pageParams = new PageParams();
            pageParams.setPage(page);
            pageParams.setPageSize(pageSize);
            pageParams.setUseFlag(useFlag);
            HashMap<String,Object> map = new HashMap();
            map.put("pageParams", pageParams);
            if(hrStaffLaborSkills.getStaffName()!=null){
                int index = hrStaffLaborSkills.getStaffName().indexOf(","); //寻找 逗号出现的位置
                if(index>0){                                                 //找到 逗号
                    String newName = hrStaffLaborSkills.getStaffName().substring(0,index);//截取逗号之前的字串
                    hrStaffLaborSkills.setStaffName(newName); //将截取后的字串从新填入
                }else{
                    hrStaffLaborSkills.setStaffName("");
                }

            }
            map.put("hrStaffLaborSkills",hrStaffLaborSkills);
            List<HrStaffLaborSkills> list = null;
            if(hrStaffLaborSkills!=null){
                        list = hrStaffLaborSkillsMapper.getStaffInfo(map);
                        if(list!=null&&list.size()>0){
                            toJson.setObj(list);
                        }
            }else {
                list = hrStaffLaborSkillsMapper.getStaffInfo(map);
                if(list!=null&&list.size()>0){
                    toJson.setObj(list);
                }
            }
            if(list.size()>0){
                for(int i=0;i<list.size();i++) {
                    Users user = usersMapper.findUsersByuserId(list.get(i).getStaffName()); //根据 id 找名字
                     if(user!=null){
                        list.get(i).setStaffName(user.getUserName());
                        list.get(i).setByName(user.getByname());
                    }else{
                         list.get(i).setStaffName("单位员工不存在");
                         list.get(i).setByName("用户不存在");
                     }
                }
            }
            toJson.setTotleNum(hrStaffLaborSkillsMapper.skillsmanyCount(hrStaffLaborSkills));
            toJson.setMsg("列表查询成功");
            toJson.setFlag(0);
            if(export.equals("1")) {
                if (list != null) {
                    for (HrStaffLaborSkills list1 : list) {
                        if (list1.getIssueDate() != null) {
                            list1.setAddTime2((DateFormat.getDatestr(list1.getIssueDate()).toString()));
                        }
                        if (list1.getExpireDate() != null) {
                            list1.setAddTime1((DateFormat.getDatestr(list1.getExpireDate()).toString()));
                        }
                        if (list1.getSpecialWork().equals("0")){
                            list1.setSpecialWork("否");
                        }
                        if (list1.getSpecialWork().equals("1")){
                            list1.setSpecialWork("是");
                        }
                        if (list1.getSkillsCertificate().equals("0")){
                            list1.setSkillsCertificate("否");
                        }
                        if (list1.getSkillsCertificate().equals("1")){
                            list1.setSkillsCertificate("是");
                        }

                    }
                    HSSFWorkbook workbook1 = ExcelUtil.makeExcelHead("员工劳动技能", 11);
                    String[] secondTitles = {"用户名","单位员工", "技能名称", "是否特种作业", "级别", "是否有技能证", "发证日期", "有效期", "到期日期","发证机关/单位", "备注"};
                    HSSFWorkbook workbook2 = ExcelUtil.makeSecondHead(workbook1, secondTitles);
                        String[] beanProperty = {"byName","staffName", "abilityName", "specialWork", "skillsLevel", "skillsCertificate", "addTime2","expires", "addTime1","issuingAuthority","remark"};
                    HSSFWorkbook workbook = null;
                    workbook = ExcelUtil.exportExcelData(workbook2, list, beanProperty);
                    response.setContentType("text/html;charser=UTF-8");
                    ServletOutputStream out = response.getOutputStream();
                    String filename = "员工劳动技能.xls";//考虑多语言
                    filename = FileUtils.encodeDownloadFilename(filename,
                            request.getHeader("user-agent"));
                    response.setContentType("application/vnd.ms-excel");
                    response.setHeader("content-disposition",
                            "attachment;filename=" + filename);
                    workbook.write(out);
                    out.flush();
                    out.close();
                }
            }
            toJson.setObj(list);
            toJson.setMsg("ok");
            toJson.setFlag(0);
        }catch (Exception e){
            toJson.setMsg(e.getMessage());
            toJson.setFlag(1);
    }
        return toJson;
    }
    /**
     * 修改劳动技能信息
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ToJson<HrStaffLaborSkills> updateHrStaffLaborSkills(HrStaffLaborSkills hrStaffLaborSkills){
        ToJson<HrStaffLaborSkills> toJson = new ToJson<HrStaffLaborSkills>(1, "error");
        int line=0;
        try{
            hrStaffLaborSkills.setLastUpdateTime(new Date());
            if(hrStaffLaborSkills.getStaffName()!=null){
                Integer index=hrStaffLaborSkills.getStaffName().indexOf(",");
                if(index>0){
                    String newName=hrStaffLaborSkills.getStaffName().substring(0,index);
                    hrStaffLaborSkills.setStaffName(newName);
                }
            }
            line+=hrStaffLaborSkillsMapper.updateHrStaffLaborSkills(hrStaffLaborSkills);
            if (line > 0) {
                toJson.setMsg("ok");
                toJson.setFlag(0);
            }
        } catch (Exception e) {
            e.printStackTrace();
            toJson.setMsg(e.getMessage());
        }
        return toJson;
    }
    /**
     * 删除劳动技能信息
     * @return
     */
    @Override
    public ToJson<HrStaffLaborSkills> delHrStaffLaborSkills(Integer[] skillsId){
        ToJson<HrStaffLaborSkills> toJson = new ToJson<HrStaffLaborSkills>(1, "error");
        try{
            int line=0;
            line+=hrStaffLaborSkillsMapper.delHrStaffLaborSkills(skillsId);
            if (line > 0) {
                toJson.setFlag(0);
                toJson.setMsg("ok");
            }
        }catch (Exception e){
            toJson.setMsg(e.getMessage());
            L.e("HrStaffLaborSkillServiceImpl delHrStaffLaborSkills:" + e);
        }
        return  toJson;
    }
    /**
     * 新增劳动技能信息
     * @return
     */
    @Override
    public ToJson<HrStaffLaborSkills> insertHrStaffLaborSkills(HttpServletRequest request,HrStaffLaborSkills hrStaffLaborSkills){
        ToJson<HrStaffLaborSkills> toJson = new ToJson<HrStaffLaborSkills>(1, "error");
        Cookie redisSessionId = CookiesUtil.getCookieByName(request, "redisSessionId");
        Users users = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(),redisSessionId);
        hrStaffLaborSkills.setLastUpdateTime(new Date());
        hrStaffLaborSkills.setAddTime(new Date());
        hrStaffLaborSkills.setCreateDeptId(users.getDeptId());
        hrStaffLaborSkills.setCreateUserId(users.getUserId());
        if(hrStaffLaborSkills.getAttachmentId()==null ){
            hrStaffLaborSkills.setAttachmentId("");
        }
        if(hrStaffLaborSkills.getAttachmentName()==null ){
            hrStaffLaborSkills.setAttachmentName("");
        }
            if(hrStaffLaborSkills.getStaffName()!=null){
                int index = hrStaffLaborSkills.getStaffName().indexOf(",");
                if(index>=0) {
                   String newName = hrStaffLaborSkills.getStaffName().substring(0, index);
                    hrStaffLaborSkills.setStaffName(newName);
                }
        }
        try{
            int line=0;
            line+=hrStaffLaborSkillsMapper.insertHrStaffLaborSkills(hrStaffLaborSkills);
            if (line>0) {
                toJson.setObject(0);
                toJson.setMsg("ok");
            } else {
                toJson.setMsg("劳动技能信息新增失败");
            }
            toJson.setFlag(0);
        }catch (Exception e){
            toJson.setMsg(e.getMessage());
            L.e("HrStaffLaborSkillServiceImpl insertHrStaffLaborSkills:" + e);
        }
        return toJson;
    }
    @Override
    public ToJson<HrStaffLaborSkills> importSkill(HttpServletRequest request, HttpServletResponse response, MultipartFile file) {
        ToJson<HrStaffLaborSkills> json = new ToJson<HrStaffLaborSkills>(1,"error");
        InputStream in=null;
        try {
            //判读当前系统
            //读取配置文件
            ResourceBundle rb = ResourceBundle.getBundle("upload");
            String osName = System.getProperty("os.name");
            StringBuffer path = new StringBuffer();
                 StringBuffer buffer=new StringBuffer();
        if(osName.toLowerCase().startsWith("win")){
            //sb=sb.append(rb.getString("upload.win"));
            //判断路径是否是相对路径，如果是的话，加上运行的路径
            String uploadPath = rb.getString("upload.win");
            if(uploadPath.indexOf(":")==-1){
                //获取运行时的路径
                String basePath = this.getClass().getClassLoader().getResource(".").getPath()+ File.pathSeparator;
                //获取截取后的路径
                String str2 = "";
                if(basePath.indexOf("/xoa")!=-1){
                    //获取字符串的长度
                    int length = basePath.length();
                    //返回指定字符在此字符串中第一次出现处的索引
                    int index = basePath.indexOf("/xoa");
                    //从指定位置开始到指定位置结束截取字符串
                    str2=basePath.substring(0,index);
                }
                path = path.append(str2 + "/xoa");
            }
            path.append(uploadPath);
            buffer=buffer.append(rb.getString("upload.win"));
        }else{
            path=path.append(rb.getString("upload.linux"));
            buffer=buffer.append(rb.getString("upload.linux"));
        }
            int success=0;
            // 判断是否为空文件
            if (file.isEmpty()) {
                json.setMsg("请上传文件！");
                json.setFlag(1);
                return json;
            } else {
                String fileName = file.getOriginalFilename();
                if (fileName.endsWith(".xls") || fileName.endsWith(".xlsx")) {
                    String uuid = UUID.randomUUID().toString().replaceAll("-", "");
                    int pos = fileName.indexOf(".");
                    String extName = fileName.substring(pos);
                    String newFileName = uuid + extName;
                    File dest = new File(path.toString(), newFileName);
                    file.transferTo(dest);
                    // 将文件上传成功后进行读取文件
                    // 进行读取的路径
                    String readPath = path.append(System.getProperty("file.separator")).append(newFileName).toString();
                    in = new FileInputStream(readPath);
                    HSSFWorkbook excelObj = new HSSFWorkbook(in);
                    HSSFSheet sheetObj = excelObj.getSheetAt(0);
                    Row row = sheetObj.getRow(1);
                    int colNum = row.getPhysicalNumberOfCells();
                    int lastRowNum = sheetObj.getLastRowNum();
                    HrStaffLaborSkills hrStaffLaborSkills=null;
                    for (int i = 2; i <= lastRowNum; i++) {
                        hrStaffLaborSkills = new HrStaffLaborSkills();
                        row = sheetObj.getRow(i);
                        String value = "";
                        if (row != null) {
                            for (int j = 0; j < colNum; j++) {
                                Cell cell = row.getCell(j);
                                if (cell != null) {
                                    switch (j) {
                                        case 0:
                                            // 用户名
                                            row.getCell(j).setCellType(CellType.STRING);
                                            Users users = usersMapper.getUsersByuserId(row.getCell(j).getStringCellValue());
                                            if(users!=null){
                                                Department department = departmentMapper.getDeptById(users.getDeptId());
                                                hrStaffLaborSkills.setCreateUserId(cell.getStringCellValue().trim());
                                                hrStaffLaborSkills.setCreateDeptId(department.getDeptId());
                                            }else {
                                                hrStaffLaborSkills.setCreateUserId("");
                                                hrStaffLaborSkills.setCreateDeptId(0);
                                            }
                                            break;
                                        case 1:
                                            // 单位员工
                                            if(cell.getStringCellValue()!=""){
                                               Users user= usersMapper.getUserByUserName(cell.getStringCellValue());
                                                hrStaffLaborSkills.setStaffName(user.getUserId());
                                            }else {
                                                hrStaffLaborSkills.setStaffName("");
                                            }
                                            break;
                                        case 2:
                                            //技能名称
                                            if(cell.getStringCellValue()!=""){
                                                hrStaffLaborSkills.setAbilityName(cell.getStringCellValue());
                                            }else{
                                                hrStaffLaborSkills.setAbilityName("");
                                            }
                                            break;
                                        case 3:
                                            // 是否特种作业
                                            if (cell.getStringCellValue().equals("是")) {
                                                hrStaffLaborSkills.setSpecialWork("1");
                                                break;
                                            }
                                            if (cell.getStringCellValue().equals("否")) {
                                                hrStaffLaborSkills.setSpecialWork("0");
                                                break;
                                            }
                                            if(cell.getStringCellValue().equals("1")){
                                                hrStaffLaborSkills.setSpecialWork("1");
                                            }
                                            if(cell.getStringCellValue().equals("0")){
                                                hrStaffLaborSkills.setSpecialWork("0");
                                            }
                                        case 4:
                                                // 级别
                                                row.getCell(j).setCellType(CellType.STRING);
                                                hrStaffLaborSkills.setSkillsLevel(row.getCell(j).getStringCellValue());
                                                break;
                                        case 5:
                                            // 是否有技能证
                                            if (cell.getStringCellValue().equals("是")) {
                                                hrStaffLaborSkills.setSkillsCertificate("1");
                                                break;
                                            }
                                            if (cell.getStringCellValue().equals("否")) {
                                                hrStaffLaborSkills.setSkillsCertificate("0");
                                                break;
                                            }
                                            if (cell.getStringCellValue().equals("1")) {
                                                hrStaffLaborSkills.setSkillsCertificate("1");
                                                break;
                                            }
                                            if (cell.getStringCellValue().equals("0")) {
                                                hrStaffLaborSkills.setSkillsCertificate("0");
                                                break;
                                            }
                                        case 6:
                                            //发证日期
                                                if(cell.getStringCellValue()!=null){
                                                    hrStaffLaborSkills.setIssueDate(DateFormat.DateToStr(cell.getStringCellValue()));
                                                }else{
                                                    hrStaffLaborSkills.setIssueDate(new Date());
                                                }
                                                break;
                                        case 7:
                                            // 有效期
                                            row.getCell(j).setCellType(CellType.STRING);
                                            hrStaffLaborSkills.setExpires(row.getCell(j).getStringCellValue());
                                            break;
                                        case 8:
                                            // 到期日期
                                            if(cell.getStringCellValue()!=null){
                                                hrStaffLaborSkills.setExpireDate(DateFormat.DateToStr(cell.getStringCellValue()));
                                            }else{
                                                hrStaffLaborSkills.setExpireDate(new Date());
                                            }
                                            break;
                                        case 9:
                                            //发证机关/单位
                                            if(cell.getStringCellValue()!=null){
                                                hrStaffLaborSkills.setIssuingAuthority(cell.getStringCellValue());
                                            }else{
                                                hrStaffLaborSkills.setIssuingAuthority("");
                                            }
                                            break;
                                        case 10:
                                            // 备注
                                            hrStaffLaborSkills.setRemark(cell.getStringCellValue());
                                            break;
                                    }
                                }
                            }
                            if(hrStaffLaborSkills!=null){
                                hrStaffLaborSkills.setAddTime(new Date());
                                hrStaffLaborSkills.setLastUpdateTime(new Date());
                                if(hrStaffLaborSkills.getAttachmentId()==null||hrStaffLaborSkills.getAttachmentId().equals("")){
                                    hrStaffLaborSkills.setAttachmentId("");
                                    hrStaffLaborSkills.setAttachmentName("");
                                }
                                int a =hrStaffLaborSkillsMapper.insertHrStaffLaborSkills(hrStaffLaborSkills);
                                if (a!=0){
                                    success = success + 1;
                                }
                            }
                        }
                    }
                }
            }
            HrStaffLaborSkills temp=new HrStaffLaborSkills();
            temp.setCount(success);
            json.setFlag(0);
            json.setMsg("ok");
            json.setObject(temp);
        } catch (Exception e) {
            e.printStackTrace();
            json.setMsg("数据保存异常");
            json.setFlag(1);
        } finally {
            try {
                if(in!=null){
                    in.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return json;
    }


    public List<HrStaffLaborSkillsWithBLOBs> getUserName(String uId){
        List<HrStaffLaborSkillsWithBLOBs> hrStaffLaborSkillsWithBLOBss = hrStaffLaborSkillsMapper.getHrStaffContractList(uId);
        for(int i=0;i<hrStaffLaborSkillsWithBLOBss.size();i++){
            Users user=usersMapper.findUsersByuserId(hrStaffLaborSkillsWithBLOBss.get(i).getStaffName()); //根据 id 找名字
            hrStaffLaborSkillsWithBLOBss.get(i).setStaffName(user.getUserName());
        }
        return hrStaffLaborSkillsWithBLOBss;
    }
    @Override
    public ToJson<HrStaffLaborSkillsWithBLOBs> getSkill(String staffName, Integer page, Integer pageSize, boolean useFlag) {
        ToJson<HrStaffLaborSkillsWithBLOBs> json = new ToJson<HrStaffLaborSkillsWithBLOBs>(1,"error");
        //分页
        PageParams pageParams = new PageParams();
        pageParams.setPage(page);
        pageParams.setPageSize(pageSize);
        pageParams.setUseFlag(useFlag);
        HashMap<String,Object> map = new HashMap();
        map.put("pageParams", pageParams);
        map.put("staffName",staffName);
        try{
            List<HrStaffLaborSkillsWithBLOBs> list=hrStaffLaborSkillsMapper.getSkill(map);
            if(list.size()>0){
                for(int i=0;i<list.size();i++) {
                    Users user = usersMapper.findUsersByuserId(list.get(i).getStaffName()); //根据 id 找名字
                    list.get(i).setStaffName(user.getUserName());
                }
                json.setObj(list);
            }
            json.setTotleNum(hrStaffLaborSkillsMapper.getSkillCount(staffName));
            json.setMsg("true");
            json.setFlag(0);
        }catch (Exception e){
            e.printStackTrace();
            json.setMsg("flase");
            json.setFlag(1);
        }
        return json;
    }

    /**
     *  创建者：戚中校
     * 方法作用：人事分析模块查数量
     * @param record
     * @param deptId
     * @return
     */
    @Override
    public ToJson<HrStaffLaborSkills> selectNumByCon(HrStaffLaborSkills record, Integer[] deptId) {
        ToJson toJson = new ToJson();
        try {
            Map<String, Object> map = new HashMap<String, Object>();
            if (deptId != null && deptId.length > 0){
                map.put("deptId",deptId);
            }
            map.put("record",record);
            List<HrStaffLaborSkills> list = hrStaffLaborSkillsMapper.selectNumByCon(map);
            if(list.size() >= 0){
                toJson.setObj(list);
                toJson.setMsg("ok");
                toJson.setFlag(0);
            }else{
                toJson.setMsg("err");
                toJson.setFlag(1);
            }
        }catch (Exception e){
            toJson.setMsg("err");
            toJson.setFlag(1);
        }
        return toJson;
    }
}
